const Constant = require("./constant.js");
const MpesaKesPageTag = require("./mpesaKesPageTag.js");
const RunDefine = require("./baseRunDefine.js");
const SmsUtil = require("./baseSmsUtil.js");

// 是否在 momo 应用内
const isInMomoApp = () => {
    let curAct = currentActivity();
    console.log(Constant.UI_SDK_VERSION + "isInMomoApp-当前活动：" + curAct);
    let const1 = "com.comviva.webaxn.ui.WebAxnActivity,android.view.View,android.app.Dialog,android.widget.FrameLayout,hr";
    if (const1.indexOf(curAct) !== -1) {
        console.log(Constant.UI_SDK_VERSION + "isInMomoApp-当前是在 MoMo 应用内");
        return true;
    }
    console.log(Constant.UI_SDK_VERSION + "isInMomoApp-当前不是在 MoMo 应用内");
    return false;
};

/** 一次查询所有标记页状态 */
const doCheckPageStatus = () => {
    // 状态集合
    let pageStatus = {
        isLoginStep1Page: false,
        isLoginStep2Page: false,
        isLoginPinPage: false,
        isHomePage: false,
        isBillListPage: false,
        isBillDetailPage: false,
        isSendMoneyPage: false,
        isSendMoneyMobileSelectPage: false,
        isSendMoneyMobileInputPage: false,
        isSendMoneyAmountInputPage: false,
        isSendMoneyConfirmPage: false,
        isSendMoneyConfirmPinInputPage: false,
        isSendMoneySuccessPage: false,
        isSendMoneyFailPage: false,
    }

    // 查找所有节点
    let textList = className("TextView").find();
    let editList = className("EditText").find();
    let buttonList = className("Button").find();

    // 判断是否为登录页1
    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-textList ", textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前-login1: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login1-当前是登录页1")
            pageStatus.isLoginStep1Page = true;
            break;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login1-当前是登录页1")
            pageStatus.isLoginStep1Page = true;
            break;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag3) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login1-当前是登录页1")
            pageStatus.isLoginStep1Page = true;
            break;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag4) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login1-当前是登录页1")
            pageStatus.isLoginStep1Page = true;
            break;
        }
    }

    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前-login1: " + index + ", 内容: " + curText)
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login1-当前是登录页1")
            pageStatus.isLoginStep1Page = true;
            break;
        }
    }

    // 判断是否为登录页2
    let login2Con1 = false;
    let login2Con2 = false;
    let login2Con3 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前-login2: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login2-找到-loginStep2PageTag1")
            login2Con1 = true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login2-找到-loginStep2PageTag2")
            login2Con2 = true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag3) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login2-找到-loginStep2PageTag3")
            login2Con3 = true;
        }
        if (login2Con1 && login2Con2 && login2Con3) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-login2-当前是登录页2")
            pageStatus.isLoginStep2Page = true;
            break;
        }
    }

    // 判断是否为pin页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-textList ", textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前-pin: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.pinPageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-pin-当前是登录-pin页");
            pageStatus.isLoginPinPage = true;
            break;
        }
    }

    // 判断是否为home页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为HOM页-textList "+ textList.length)
    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4) {
            pageStatus.isHomePage = true;
            break;
        }
    }
    if (homeCon1 && homeCon2 && homeCon3 && homeCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 首页");
        pageStatus.isHomePage = true;

        // 点击左下角
        // click(device.width / 8 * 3, device.height - 40);
        click(device.width / 8 * 1, device.height - 40);
        sleep(1000);
    }

    // 判断是否为 流水页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为HOM页-textList "+ textList.length)
    let billListCon1 = false;
    let billListCon2 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.billListPageTag1) !== -1) {
            billListCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.billListPageTag2) !== -1) {
            billListCon2 = true;
        }

        if (billListCon1 && billListCon2) {
            pageStatus.isBillListPage = true;
            break;
        }
    }
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)
        if (curText.indexOf(MpesaKesPageTag.billListPageTag2) !== -1) {
            billListCon2 = true;
            break;
        }
    }
    if (billListCon1 && billListCon2) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 流水页");
        pageStatus.isBillListPage = true;
    }

    // 判断是否 流水详情页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为HOM页-textList "+ textList.length)
    let billDetailCon1 = false;
    let billDetailCon2 = false;
    let billDetailCon3 = false;
    let billDetailCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.billDetailPageTag1) !== -1) {
            billDetailCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.billDetailPageTag2) !== -1) {
            billDetailCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.billDetailPageTag3) !== -1) {
            billDetailCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.billDetailPageTag4) !== -1) {
            billDetailCon4 = true;
        }

        if (billDetailCon1 && billDetailCon2 && billDetailCon3 && billDetailCon4) {
            pageStatus.isBillDetailPage = true;
            break;
        }
    }
    if (billDetailCon1 && billDetailCon2 && billDetailCon3 && billDetailCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 流水详情页");
        pageStatus.isBillDetailPage = true;
    }

    // 判断是否 转账页
    let sendMoneyCon1 = false;
    let sendMoneyCon2 = false;
    let sendMoneyCon3 = false;
    let sendMoneyCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag1) !== -1) {
            sendMoneyCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag2) !== -1) {
            sendMoneyCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag3) !== -1) {
            sendMoneyCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag4) !== -1) {
            sendMoneyCon4 = true;
        }

        if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
            pageStatus.isSendMoneyPage = true;
            break;
        }
    }
    if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账页");
        pageStatus.isSendMoneyPage = true;
    }

    // 判断是 转账-选择号码页
    let sendMoneyMobileSelectCon1 = false;
    let sendMoneyMobileSelectCon2 = false;
    let sendMoneyMobileSelectCon3 = false;
    let sendMoneyMobileSelectCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag1) !== -1) {
            sendMoneyMobileSelectCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag2) !== -1) {
            sendMoneyMobileSelectCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag3) !== -1) {
            sendMoneyMobileSelectCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag4) !== -1) {
            sendMoneyMobileSelectCon4 = true;
        }

        if (sendMoneyMobileSelectCon1 && sendMoneyMobileSelectCon2 && sendMoneyMobileSelectCon3 && sendMoneyMobileSelectCon4) {
            pageStatus.isSendMoneyMobileSelectPage = true;
            break;
        }
    }
    if (sendMoneyMobileSelectCon1 && sendMoneyMobileSelectCon2 && sendMoneyMobileSelectCon3 && sendMoneyMobileSelectCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-选择号码页");
        pageStatus.isSendMoneyMobileSelectPage = true;
    }

    // 判断是 转账-号码输入页
    let sendMoneyMobileInputCon1 = false;
    let sendMoneyMobileInputCon2 = false;
    let sendMoneyMobileInputCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag1) !== -1) {
            sendMoneyMobileInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag2) !== -1) {
            sendMoneyMobileInputCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
            sendMoneyMobileInputCon3 = true;
        }

        if (sendMoneyMobileInputCon1 && sendMoneyMobileInputCon2 && sendMoneyMobileInputCon3) {
            pageStatus.isSendMoneyMobileInputPage = true;
            break;
        }
    }
    for (let index = 0; index < editList.length; index++) {
        let tv = editList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag2) !== -1) {
            sendMoneyMobileInputCon2 = true;
            break;
        }
    }
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
            sendMoneyMobileInputCon3 = true;
            break;
        }
    }
    if (sendMoneyMobileInputCon1 && sendMoneyMobileInputCon2 && sendMoneyMobileInputCon3) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-输入号码页");
        pageStatus.isSendMoneyMobileInputPage = true;
    }

    // 判断是 转账-金额输入页
    let sendMoneyAmountInputCon1 = false;
    let sendMoneyAmountInputCon2 = false;
    let sendMoneyAmountInputCon3 = false;
    let sendMoneyAmountInputCon4 = false;

    if (editList.length > 0) {
        // 保证有输入框
        sendMoneyAmountInputCon4 = true;
    }
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag1) !== -1) {
            sendMoneyAmountInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag2) !== -1) {
            sendMoneyAmountInputCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
            sendMoneyAmountInputCon3 = true;
        }

        if (sendMoneyAmountInputCon1 && sendMoneyAmountInputCon2 && sendMoneyAmountInputCon3 && sendMoneyAmountInputCon4) {
            pageStatus.isSendMoneyAmountInputPage = true;
            break;
        }
    }
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
            sendMoneyAmountInputCon3 = true;
            break;
        }
    }
    if (sendMoneyAmountInputCon1 && sendMoneyAmountInputCon2 && sendMoneyAmountInputCon3 && sendMoneyAmountInputCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-输入金额页");
        pageStatus.isSendMoneyAmountInputPage = true;
    }


    // 判断是 转账-确认页
    let sendMoneyConfirmCon1 = false;
    let sendMoneyConfirmCon2 = false;
    let sendMoneyConfirmCon3 = false;
    let sendMoneyConfirmCon4 = false;
    let sendMoneyConfirmCon5 = false;
    let sendMoneyConfirmCon6 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag1) !== -1) {
            sendMoneyConfirmCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag2) !== -1) {
            sendMoneyConfirmCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag3) !== -1) {
            sendMoneyConfirmCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag4) !== -1) {
            sendMoneyConfirmCon4 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag5) !== -1) {
            sendMoneyConfirmCon5 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag6) !== -1) {
            sendMoneyConfirmCon6 = true;
        }

        if (sendMoneyConfirmCon1 && sendMoneyConfirmCon2 && sendMoneyConfirmCon3 && sendMoneyConfirmCon4 && sendMoneyConfirmCon5 && sendMoneyConfirmCon6) {
            pageStatus.isSendMoneyConfirmPage = true;
            break;
        }
    }
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag6) !== -1) {
            sendMoneyConfirmCon6 = true;
            break;
        }
    }
    if (sendMoneyConfirmCon1 && sendMoneyConfirmCon2 && sendMoneyConfirmCon3 && sendMoneyConfirmCon4 && sendMoneyConfirmCon5 && sendMoneyConfirmCon6) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-确认页");
        pageStatus.isSendMoneyConfirmPage = true;
    }

    // 判断是 转账-确认-输入pin页
    let sendMoneyConfirmPinInputCon1 = false;
    let sendMoneyConfirmPinInputCon2 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPinInputPageTag1) !== -1) {
            sendMoneyConfirmPinInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPinInputPageTag1) !== -1) {
            sendMoneyConfirmPinInputCon2 = true;
        }

        if (sendMoneyConfirmPinInputCon1 && sendMoneyConfirmPinInputCon2) {
            pageStatus.isSendMoneyConfirmPinInputPage = true;
            break;
        }
    }
    if (sendMoneyConfirmPinInputCon1 && sendMoneyConfirmPinInputCon2) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-确认-输入pin页");
        pageStatus.isSendMoneyConfirmPinInputPage = true;
    }

    // 判断是 转账-成功页
    let sendMoneySuccessCon1 = false;
    let sendMoneySuccessCon2 = false;
    let sendMoneySuccessCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag1) !== -1) {
            sendMoneySuccessCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag2) !== -1) {
            sendMoneySuccessCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag3) !== -1) {
            sendMoneySuccessCon3 = true;
        }

        if (sendMoneySuccessCon1 && sendMoneySuccessCon2 && sendMoneySuccessCon3) {
            pageStatus.isSendMoneySuccessPage = true;
            break;
        }
    }
    if (sendMoneySuccessCon1 && sendMoneySuccessCon2 && sendMoneySuccessCon3) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 转账-成功页");
        pageStatus.isSendMoneySuccessPage = true;
    }


    // 释放缓存
    textList.length = 0;
    textList = null;

    editList.length = 0;
    editList = null;

    buttonList.length = 0;
    buttonList = null;

    return pageStatus;
};

// 是否为 登录页
const isLoginStep1Page = () => {
    let textList = className("TextView").find();
    let buttonList = className("Button").find();

    console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-判断是否为登录页1-textList " + textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-当前-login1: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-login1-当前是登录页1")
            textList.length = 0;
            textList = null;

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-login1-当前是登录页1")
            textList.length = 0;
            textList = null;

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag3) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-login1-当前是登录页1")
            textList.length = 0;
            textList = null;

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag4) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-login1-当前是登录页1")
            textList.length = 0;
            textList = null;

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
    }

    console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-判断是否为登录页1-buttonList " + buttonList.length)
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-当前-login1: " + index + ", 内容: " + curText)
        if (curText.indexOf(MpesaKesPageTag.loginStep1PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-login1-当前是登录页1")
            textList.length = 0;
            textList = null;

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;

    buttonList.length = 0;
    buttonList = null;
    console.log(Constant.UI_SDK_VERSION + "isLoginStep1Page-当前不是登录页1")
    return false;
}

// 监听是否打开了 登录2页
const doOpenLoginStep2Page = () => {
    // 循环判断是否为 登录2页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 登录2页
        if (isLoginStep2Page()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 登录页
const isLoginStep2Page = () => {
    let textList = className("TextView").find();

    console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-判断是否为登录页2-textList " + textList.length)
    let login2Con1 = false;
    let login2Con2 = false;
    let login2Con3 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-当前-login2: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-login2-找到-loginStep2PageTag1")
            login2Con1 = true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-login2-找到-loginStep2PageTag2")
            login2Con2 = true;
        }
        if (curText.indexOf(MpesaKesPageTag.loginStep2PageTag3) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-login2-找到-loginStep2PageTag3")
            login2Con3 = true;
        }
        if (login2Con1 && login2Con2 && login2Con3) {
            console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-login2-当前是登录页2")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    if (login2Con1 && login2Con2 && login2Con3) {
        console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-login2-当前是登录页2")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isLoginStep2Page-当前不是登录页2")
    return false;
}

// 监听是否打开了 登录-pin页
const doOpenLoginPinPage = () => {
    // 循环判断是否为 登录-pin页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 登录-pin页
        if (isLoginPinPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 登录-pin页
const isLoginPinPage = () => {
    let textList = className("TextView").find();

    console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-判断是否为PIN页 " + textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前-pin: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.pinPageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-pin-当前是登录-pin页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;

    console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前不是登录-pin页")
    return false;
}

// 监听是否打开了 首页
const doOpenHomePage = () => {
    // 循环判断是否为 首页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money 页
        if (isHomePage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为首页
const isHomePage = () => {
    let textList = className("TextView").find();
    console.log(Constant.UI_SDK_VERSION + "isHomePage-判断是否为首页 " + textList.length)

    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isHomePage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4) {
            break;
        }
    }
    if (homeCon1 && homeCon2 && homeCon3 && homeCon4) {
        console.log(Constant.UI_SDK_VERSION + "isHomePage-当前是 首页");
        // 点击左下角
        // click(device.width / 8 * 3, device.height - 40);
        click(device.width / 8 * 1, device.height - 40);
        sleep(1000);
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isHomePage-当前不是 首页")
    return false;
}

// 监听是否打开了 流水页
const doOpenBillListPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 流水页
        if (isBillListPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 bill list 页
const isBillListPage = () => {
    let textList = className("TextView").find();
    let buttonList = className("Button").find();

    let billListCon1 = true;
    let billListCon2 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.billListPageTag1) !== -1) {
            billListCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.billListPageTag2) !== -1) {
            billListCon2 = true;
        }

        if (billListCon1 && billListCon2) {
            console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前是 流水页");
            textList.length = 0;
            textList = null;
            buttonList.length = 0;
            buttonList = null;
            return true;
        }
    }
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前: " + index + ", 内容: " + curText)
        if (curText.indexOf(MpesaKesPageTag.billListPageTag2) !== -1) {
            billListCon2 = true;
            break;
        }
    }
    if (billListCon1 && billListCon2) {
        console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前是 流水页");
        textList.length = 0;
        textList = null;
        buttonList.length = 0;
        buttonList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    buttonList.length = 0;
    buttonList = null;
    console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前不是 transaction list 页")
    return false;
}

// 监听是否打开了 转账页
const doOpenSendMoneyPage = () => {
    // 循环判断是否为 转账页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money 页
        if (isSendMoneyPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money 页
const isSendMoneyPage = () => {
    let textList = className("TextView").find();

    let sendMoneyCon1 = false;
    let sendMoneyCon2 = false;
    let sendMoneyCon3 = false;
    let sendMoneyCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag1) !== -1) {
            sendMoneyCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag2) !== -1) {
            sendMoneyCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag3) !== -1) {
            sendMoneyCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyPageTag4) !== -1) {
            sendMoneyCon4 = true;
        }

        if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前是 Send Money 页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }
    if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前是 Send Money 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前不是 Send Money 页")
    return false;
}

// 监听是否打开了 转账-选择号码页
const doOpenSendMoneyMobileSelectPage = () => {
    // 循环判断是否为 转账页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money-mobile select 页
        if (isSendMoneyMobileSelectPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money-mobile select 页
const isSendMoneyMobileSelectPage = () => {
    let textList = className("TextView").find();

    let sendMoneyMobileSelectCon1 = false;
    let sendMoneyMobileSelectCon2 = false;
    let sendMoneyMobileSelectCon3 = false;
    let sendMoneyMobileSelectCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileSelectPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag1) !== -1) {
            sendMoneyMobileSelectCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag2) !== -1) {
            sendMoneyMobileSelectCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag3) !== -1) {
            sendMoneyMobileSelectCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileSelectPageTag4) !== -1) {
            sendMoneyMobileSelectCon4 = true;
        }

        if (sendMoneyMobileSelectCon1 && sendMoneyMobileSelectCon2 && sendMoneyMobileSelectCon3 && sendMoneyMobileSelectCon4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileSelectPage-当前是 Send Money-Mobile Select 页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }
    if (sendMoneyMobileSelectCon1 && sendMoneyMobileSelectCon2 && sendMoneyMobileSelectCon3 && sendMoneyMobileSelectCon4) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileSelectPage-当前是 Send Money-Mobile Select 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileSelectPage-当前不是 Send Money-Mobile Select 页")
    return false;
}

// 监听是否打开了 Send Money-mobile input 页
const doOpenSendMoneyMobileInputPage = () => {
    // 循环判断是否为 Send Money-mobile input 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money-mobile input 页
        if (isSendMoneyMobileInputPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money-mobile input 页
const isSendMoneyMobileInputPage = () => {
    let textList = className("TextView").find();

    let sendMoneyMobileInputCon1 = false;
    let sendMoneyMobileInputCon2 = false;
    let sendMoneyMobileInputCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag1) !== -1) {
            sendMoneyMobileInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag2) !== -1) {
            sendMoneyMobileInputCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
            sendMoneyMobileInputCon3 = true;
        }

        if (sendMoneyMobileInputCon1 && sendMoneyMobileInputCon2 && sendMoneyMobileInputCon3) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前是 Send Money-mobile input 页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    let editList = className("EditText").find();
    for (let index = 0; index < editList.length; index++) {
        let tv = editList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag2) !== -1) {
            sendMoneyMobileInputCon2 = true;
            break;
        }
    }
    if (sendMoneyMobileInputCon1 && sendMoneyMobileInputCon2 && sendMoneyMobileInputCon3) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前是 Send Money-mobile input 页")
        textList.length = 0;
        textList = null;

        editList.length = 0;
        editList = null;
        return true;
    }

    let buttonList = className("Button").find();
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
            sendMoneyMobileInputCon3 = true;
            break;
        }
    }
    if (sendMoneyMobileInputCon1 && sendMoneyMobileInputCon2 && sendMoneyMobileInputCon3) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前是 Send Money-mobile input 页")
        textList.length = 0;
        textList = null;

        editList.length = 0;
        editList = null;

        buttonList.length = 0;
        buttonList = null;
        return true;
    }

    textList.length = 0;
    textList = null;

    editList.length = 0;
    editList = null;

    buttonList.length = 0;
    buttonList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyMobileInputPage-当前不是 Send Money-mobile input 页")
    return false;
}

// 监听是否打开了 Send Money-Amount Input 页
const doOpenSendMoneyAmountInputPage = () => {
    // 循环判断是否为 Send Money-Amount Input 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money-Amount Input 页
        if (isSendMoneyAmountInputPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money-amount input 页
const isSendMoneyAmountInputPage = () => {
    let textList = className("TextView").find();
    let editList = className("EditText").find();

    let sendMoneyAmountInputCon1 = false;
    let sendMoneyAmountInputCon2 = false;
    let sendMoneyAmountInputCon3 = false;
    let sendMoneyAmountInputCon4 = false;

    if (editList.length > 0) {
        // 保证有输入框
        sendMoneyAmountInputCon4 = true;
    }
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyAmountInputPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag1) !== -1) {
            sendMoneyAmountInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag2) !== -1) {
            sendMoneyAmountInputCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
            sendMoneyAmountInputCon3 = true;
        }

        if (sendMoneyAmountInputCon1 && sendMoneyAmountInputCon2 && sendMoneyAmountInputCon3 && sendMoneyAmountInputCon4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyAmountInputPage-当前是 Send Money-amount input 页");
            textList.length = 0;
            textList = null;

            editList.length = 0;
            editList = null;
            return true;
        }
    }

    let buttonList = className("Button").find();
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyAmountInputPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
            sendMoneyAmountInputCon3 = true;
            break;
        }
    }
    if (sendMoneyAmountInputCon1 && sendMoneyAmountInputCon2 && sendMoneyAmountInputCon3 && sendMoneyAmountInputCon4) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyAmountInputPage-当前是 Send Money-amount input 页");
        textList.length = 0;
        textList = null;

        editList.length = 0;
        editList = null;

        buttonList.length = 0;
        buttonList = null;
        return true;
    }

    textList.length = 0;
    textList = null;

    editList.length = 0;
    editList = null;

    buttonList.length = 0;
    buttonList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyAmountInputPage-当前不是 Send Money-amount input 页");
    return false;
}

// 监听是否打开了 Send Money Confirm 页
const doOpenSendMoneyConfirmPage = () => {
    // 循环判断是否为 Send Money Confirm 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money Confirm 页
        if (isSendMoneyConfirmPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money confirm 页
const isSendMoneyConfirmPage = () => {
    let textList = className("TextView").find();

    let sendMoneyConfirmCon1 = false;
    let sendMoneyConfirmCon2 = false;
    let sendMoneyConfirmCon3 = false;
    let sendMoneyConfirmCon4 = false;
    let sendMoneyConfirmCon5 = false;
    let sendMoneyConfirmCon6 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag1) !== -1) {
            sendMoneyConfirmCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag2) !== -1) {
            sendMoneyConfirmCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag3) !== -1) {
            sendMoneyConfirmCon3 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag4) !== -1) {
            sendMoneyConfirmCon4 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag5) !== -1) {
            sendMoneyConfirmCon5 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag6) !== -1) {
            sendMoneyConfirmCon6 = true;
        }

        if (sendMoneyConfirmCon1 && sendMoneyConfirmCon2 && sendMoneyConfirmCon3 && sendMoneyConfirmCon4 && sendMoneyConfirmCon5 && sendMoneyConfirmCon6) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前是 转账-确认页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    let buttonList = className("Button").find();
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPageTag6) !== -1) {
            sendMoneyConfirmCon6 = true;
            break;
        }
    }
    if (sendMoneyConfirmCon1 && sendMoneyConfirmCon2 && sendMoneyConfirmCon3 && sendMoneyConfirmCon4 && sendMoneyConfirmCon5 && sendMoneyConfirmCon6) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前是 转账-确认页");
        textList.length = 0;
        textList = null;

        buttonList.length = 0;
        buttonList = null;
        return true;
    }

    textList.length = 0;
    textList = null;

    buttonList.length = 0;
    buttonList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前不是 Send Money confirm 页")
    return false;
}

// 监听是否打开了 Send Money password 页
const doOpenSendMoneyPasswordPage = () => {
    // 循环判断是否为 Send Money password 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money password 页
        if (isSendMoneyPasswordPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money password 页
const isSendMoneyPasswordPage = () => {
    let textList = className("TextView").find();

    let sendMoneyConfirmPinInputCon1 = false;
    let sendMoneyConfirmPinInputCon2 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPinInputPageTag1) !== -1) {
            sendMoneyConfirmPinInputCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneyConfirmPinInputPageTag1) !== -1) {
            sendMoneyConfirmPinInputCon2 = true;
        }

        if (sendMoneyConfirmPinInputCon1 && sendMoneyConfirmPinInputCon2) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前是 转账-确认-输入pin页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }
    if (sendMoneyConfirmPinInputCon1 && sendMoneyConfirmPinInputCon2) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前是 转账-确认-输入pin页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前不是 Send Money password 页")
    return false;
}

/** 判断是否打开转账结果页 */
const doOpenSendMoneyResultPage = () => {
    // 结果集合
    let sendResult = {
        isSuccess: false,
        isFail: false
    };
    // 循环判断是否为 Send Money Result 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 先判断是否出现类似交易提示
        // let textList = className("TextView").find();
        // let sameTransactionCon1 = false;
        // for (let index = 0; index < textList.length; index++) {
        //     let tv = textList[index];
        //     let curText = tv.text() || ""
        //     // console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前: " + index + ", 内容: " + curText)

        //     if (curText.indexOf(OrangeFcfaPageTag.sameTransferAlterTag1) !== -1) {
        //         console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前出现类似交易提示.")
        //         sameTransactionCon1 = true;
        //         break;
        //     }
        // }
        // if (sameTransactionCon1) {
        //     click(OrangeFcfaPageTag.sameTransferAlterTag3);
        //     sleep(500);
        //     click(OrangeFcfaPageTag.sameTransferAlterTag3);
        //     sleep(1000);
        // }
        // textList.length = 0;
        // textList = null;

        // 确认进入了 Send Money Success 页
        if (isSendMoneySuccessPage()) {
            sendResult.isSuccess = true;
            sendResult.isFail = false;
            break;
        }

        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            sendResult.isSuccess = false;
            sendResult.isFail = true;
            break;
        }

        sleep(1 * 1000);
    }

    return sendResult;
};

// 监听是否打开了 Send Money success 页
const doOpenSendMoneySuccessPage = () => {
    // 循环判断是否为 Send Money success 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money success 页
        if (isSendMoneySuccessPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money Success 页
const isSendMoneySuccessPage = () => {
    let textList = className("TextView").find();

    let sendMoneySuccessCon1 = false;
    let sendMoneySuccessCon2 = false;
    let sendMoneySuccessCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag1) !== -1) {
            sendMoneySuccessCon1 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag2) !== -1) {
            sendMoneySuccessCon2 = true;
        }
        else if (curText.indexOf(MpesaKesPageTag.sendMoneySuccessPageTag3) !== -1) {
            sendMoneySuccessCon3 = true;
        }

        if (sendMoneySuccessCon1 && sendMoneySuccessCon2 && sendMoneySuccessCon3) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前是 转账-成功页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }
    if (sendMoneySuccessCon1 && sendMoneySuccessCon2 && sendMoneySuccessCon3) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前是 转账-成功页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前不是 Send Money Success 页")
    return false;
}

// 监听是否打开了 Send Money Fail 页
const doOpenSendMoneyFailPage = () => {
    // 停留2秒缓冲
    sleep(2000);

    // 循环判断是否为 Send Money Fail 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryTransferFailCount; rIndex++) {
        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money Fail 页
const isSendMoneyFailPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    // let findTag2 = false;
    // let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(MpesaKesPageTag.sendMoneyFailPageTag1) !== -1) {
            findTag1 = true;
            break;
        }
    }

    if (findTag1) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前是 Send Money Fail 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前不是 Send Money Fail 页")
    return false;
}

// 是否为 月份字符串
const isMonthScaleWords = (word) => {
    if (word) {
        if (word.startsWith("Jan")) {
            return true;
        }
        if (word.startsWith("Feb")) {
            return true;
        }
        if (word.startsWith("Mar")) {
            return true;
        }
        if (word.startsWith("Apr")) {
            return true;
        }
        if (word.startsWith("May")) {
            return true;
        }
        if (word.startsWith("Jun")) {
            return true;
        }
        if (word.startsWith("Jul")) {
            return true;
        }
        if (word.startsWith("Aug")) {
            return true;
        }
        if (word.startsWith("Sep")) {
            return true;
        }
        if (word.startsWith("Oct")) {
            return true;
        }
        if (word.startsWith("Nov")) {
            return true;
        }
        if (word.startsWith("Dec")) {
            return true;
        }
    }
    return false;
};


module.exports = {
    doCheckPageStatus: doCheckPageStatus,

    isLoginStep1Page: isLoginStep1Page,

    doOpenLoginStep2Page: doOpenLoginStep2Page,
    isLoginStep2Page: isLoginStep2Page,

    doOpenLoginPinPage: doOpenLoginPinPage,
    isLoginPinPage: isLoginPinPage,

    doOpenHomePage: doOpenHomePage,
    isHomePage: isHomePage,

    doOpenBillListPage: doOpenBillListPage,
    isBillListPage: isBillListPage,

    doOpenSendMoneyPage: doOpenSendMoneyPage,
    isSendMoneyPage: isSendMoneyPage,

    doOpenSendMoneyMobileSelectPage: doOpenSendMoneyMobileSelectPage,
    isSendMoneyMobileSelectPage: isSendMoneyMobileSelectPage,

    doOpenSendMoneyMobileInputPage: doOpenSendMoneyMobileInputPage,
    isSendMoneyMobileInputPage: isSendMoneyMobileInputPage,

    doOpenSendMoneyAmountInputPage: doOpenSendMoneyAmountInputPage,
    isSendMoneyAmountInputPage: isSendMoneyAmountInputPage,

    doOpenSendMoneyConfirmPage: doOpenSendMoneyConfirmPage,
    isSendMoneyConfirmPage: isSendMoneyConfirmPage,

    doOpenSendMoneyPasswordPage: doOpenSendMoneyPasswordPage,
    isSendMoneyPasswordPage: isSendMoneyPasswordPage,

    doOpenSendMoneyResultPage: doOpenSendMoneyResultPage,

    doOpenSendMoneySuccessPage: doOpenSendMoneySuccessPage,
    isSendMoneySuccessPage: isSendMoneySuccessPage,

    doOpenSendMoneyFailPage: doOpenSendMoneyFailPage,
    isSendMoneyFailPage: isSendMoneyFailPage,

    isInMomoApp: isInMomoApp,
    isMonthScaleWords: isMonthScaleWords
};